package com.example.administrator.fivepagelibrary.dagger;


import android.support.v4.app.Fragment;

import com.example.administrator.commonlibrary.bese.BaseAppliction;
import com.example.administrator.fivepagelibrary.dagger.component.DaggerFragmentComponent;
import com.example.administrator.fivepagelibrary.dagger.component.FragmentComponent;
import com.example.administrator.fivepagelibrary.dagger.module.ViewModule;
import com.example.administrator.fivepagelibrary.dagger.module.ViewParameterModule;
import com.example.administrator.fivepagelibrary.view.fragment.FiveFragment;

/**
 * 作者：wang_hong_wei
 * 创建时间：2018/9/12  dagger2 官网：https://google.github.io/dagger/multibindings
 * 描述：dagger2 实例化对象的帮助类  封装在基类里面
 */
public class NewFragmentInject implements FragmentComponent{

    private FragmentComponent build;

    public static NewFragmentInject getInject(){
        return new NewFragmentInject();
    }
    public  <S, T> void inject(S module, T context) {
       if (module == null) module = (S) new ViewParameterModule((Fragment) context);
        ViewModule mvpModule = new ViewModule((Fragment) context);
        build = DaggerFragmentComponent.builder().viewModule(mvpModule).viewParameterModule((ViewParameterModule) module).overallSituationComponent(BaseAppliction.getOverallSituation()).build();

        if (context instanceof FiveFragment)inject((FiveFragment) context);


    }

    @Override
    public void inject(FiveFragment fiveFragment) {
        build .inject(fiveFragment);
    }
}
